<%@page import="java.util.*"%>
<%@page import="com.ks.sgms.dao.*" %>
<%@page import="com.ks.sgms.entity.*" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>学生信息管理页</title>
</head>

<%
	StudentDao dao = new StudentDao();
	List<Student> list = new ArrayList<Student>();
	request.setCharacterEncoding("UTF-8");
	

		//获取名为"student_id"的值
		String student_id = request.getParameter("student_id");
		String class_name = request.getParameter("class_name");
		//如果student_id是空的，则代表无需查询，直接查询全部student
		//如果不是空的，则代表需要查询，仅展示查询的数据
		if((student_id==null && class_name == null) || (student_id == "" && class_name == "") ){
			list = dao.getAllStudent();
		}else{
			Student s = new Student();
			if(class_name == "" && student_id != ""){
				 s = dao.selectStuByNo(student_id);
				 list.add(s);
			}else if(class_name != "" && student_id == ""){
				list = dao.selectStuByClass(class_name);
				//new ClassDao().selectClassByName(class_name);
			}else{
				s = dao.selectStuByIdAndClass(student_id, class_name);
				list.add(s);
			}
		}
	
%>
<body>
	<div>
		<h1>学生信息管理</h1>
		<div class="box">
			<a href="student-insert.jsp" style="width:50px">
				<button>添加<tton>
			</a>	
			<form action="student.jsp" method="post">
				学号：<input  type="text"  name="student_id" value="">
				班级：<input  type="text"  name="class_name" value="">
				<input type="submit"  value="查询">
			</form>
		</div>	
		<table>
			<tr>
				<td colspan="7">数据库中数据如下所示:</td>
			</tr>
			<tr>
				<td>学号</td>
				<td>姓名</td>
				<td>性别</td>
				<td>出生日期</td>
				<td>班级</td>
				<td colspan="2">操作</td>
			</tr>
			<%for(int i = 0;i < list.size();i++){ %>
				<tr>
					<% String sex = list.get(i).sex == 0?"女":"男"; %>
					<td><%=list.get(i).student_id%></td>
					<td><%=list.get(i).student_name%></td>
					<td><%=sex%></td>
					<td><%=list.get(i).birthString%></td>
					<td><%=list.get(i).class_name%></td>
					<td>
					<a href="student-update.jsp?student_id=<%=list.get(i).student_id%>">
						<button>修改<tton>
					</a>
					</td>
					<td>
					<a href="deleteStudent?student_id_del=<%=list.get(i).student_id%>">
						<button>删除<tton>
					</a>
					</td>
				</tr>
			<%} %>
		</table>	
	</div>
</body>
<style type="text/css">
	div {
		margin: 0 auto;
		width: 80%;
	}
	
	table {
		border: 2px solid;
	}
	
	td {
		border: 1px solid;
		text-align: center;
		width: 200px;
		height: 30px;
	}
	.box{
		display: flex;
		flex-direction: row;
	}
</style>

</html>